<?php
/**
 * 系统配置控制器
 * Enter description here ...
 * @author Code.404
 *
 */
class SettingsAction extends BaseAction{
	function _init(){
		C('LOG_ADMIN') && D('Log')->writeLog();
	}
	/**
	 * 基本配置
	 * Enter description here ...
	 */
	function baseSettings(){
		if($this->_a == 'show' && $this->_t == 'page'){
			$this->display();
		}
		if($this->_a == 'exec'){

			if(IS_SAE) 
				$this->ajaxJsonReturn(300,L('CURRENT_NOT_SUPPORT_SAE'));
			if($_SESSION['super_admin'] != 'super'){//只有超级管理员可以修改
				$this->ajaxJsonReturn(300,L('NEED_SUPERMAN_AUTHORITY'));
			}	
			
			try{

				if(D('SystemSettings')->changeBaseSettings($_POST)){
					$this->ajaxJsonReturn(200 , L('ACTION_SUCCESS'),0,U('Settings/baseSettings'),'forward');
				}

				$this->ajaxJsonReturn(300,L('ACTION_FAILED'));
			}catch(Exception $e){
				$this->ajaxJsonReturn(300,L($e->getMessage()));
			}
		}
	}
	/**
	 * 个性化配置
	 * Enter description here ...
	 */
	function customization(){
		if($this->_a == 'show' && $this->_t == 'page'){
			$this->assign('config' , require __ROOT__.'/Conf/customization.config.php');
			$this->display();
		}
		if($this->_a == 'exec'){
			if(IS_SAE) 
				$this->ajaxJsonReturn(300,L('CURRENT_NOT_SUPPORT_SAE'));
			try{
				if(D('SystemSettings')->changeCustomizationSettings($_POST)){
					$this->ajaxJsonReturn(200 , L('ACTION_SUCCESS'),0,U('Settings/customization'),'forward');
				}

				$this->ajaxJsonReturn(300,L('ACTION_FAILED'));
			}catch(Exception $e){
				$this->ajaxJsonReturn(300,L($e->getMessage()));
			}
		}
	}
}